﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Communergy.Common;
using CommunergyLogicTests.MockObjects;

namespace CommunergyLogicTests
{
    public class MockUnitOfWork : IUnitOfWork
    {
		#region Fields (8) 

        List<MockHistorical> dailyCommitted = new List<MockHistorical>();
        List<MockHistorical> dailyPending = new List<MockHistorical>();
        List<MockHistorical> hourlyCommitted = new List<MockHistorical>();
        List<MockHistorical> hourlyPending = new List<MockHistorical>();
        List<MockHistorical> monthlyCommitted = new List<MockHistorical>();
        List<MockHistorical> monthlyPending = new List<MockHistorical>();
        List<MockRealtime> realtimeCommitted = new List<MockRealtime>();
        List<MockRealtime> realtimePending = new List<MockRealtime>();



		#endregion Fields 

		#region Properties (8) 

        public List<MockHistorical> DailyCommitted
        {
            get { return dailyCommitted; }
            set { dailyCommitted = value; }
        }

        public List<MockHistorical> DailyPending
        {
            get { return dailyPending; }
            set { dailyPending = value; }
        }

        public List<MockHistorical> HourlyCommitted
        {
            get { return hourlyCommitted; }
            set { hourlyCommitted = value; }
        }

        public List<MockHistorical> HourlyPending
        {
            get { return hourlyPending; }
            set { hourlyPending = value; }
        }

        public List<MockHistorical> MonthlyCommitted
        {
            get { return monthlyCommitted; }
            set { monthlyCommitted = value; }
        }

        public List<MockHistorical> MonthlyPending
        {
            get { return monthlyPending; }
            set { monthlyPending = value; }
        }

        public List<MockRealtime> RealtimeCommitted
        {
            get { return realtimeCommitted; }
            set { realtimeCommitted = value; }
        }

        public List<MockRealtime> RealtimePending
        {
            get { return realtimePending; }
            set { realtimePending = value; }
        }

		#endregion Properties 



        #region IUnitOfWork Members

        public void Save()
        {
            CommitPendingElectricity();
            ResetPendingElectricity();
        }

        private void CommitPendingElectricity()
        {
            realtimeCommitted = realtimeCommitted.Union(realtimePending).ToList();
            hourlyCommitted = hourlyCommitted.Union(hourlyPending).ToList();
            dailyCommitted = dailyCommitted.Union(dailyPending).ToList();
            monthlyCommitted = monthlyCommitted.Union(monthlyPending).ToList();
        }

        public void Rollback()
        {
            ResetPendingElectricity();

        }

        private void ResetPendingElectricity()
        {
            dailyPending = new List<MockHistorical>();
            hourlyPending = new List<MockHistorical>();
            monthlyPending = new List<MockHistorical>();
            realtimePending = new List<MockRealtime>();
        }

        #endregion

        #region IDisposable Members

        public void Dispose()
        {
            //do nothing
        }

        #endregion
    }
}
